show engines;

use test;

select database();

drop table if exists bank_account;
create table bank_account (
  id bigint primary key auto_increment,
  `name` varchar(255) not null,
  balance decimal(10, 2) not null 
);

insert into bank_account (`name`, balance) 
values ('张三', 1000),('李四', 1000);

select * from bank_account;

update bank_account set balance = balance - 100 
where `name` = '张三';
select * from bank_account;

update bank_account set balance = balance + 100
where `name` = '张三';
select * from bank_account;

show engines;

show variables like 'autocommit';

begin;

rollback;

start transaction;

commit;

start transaction;

select * from bank_account;

update bank_account set balance = balance - 100
where `name` = '张三';

update bank_account set balance = balance + 100
where `name` = '李四';

select * from bank_account;

rollback;

select * from bank_account;

begin;

select * from bank_account;

update bank_account set balance = balance - 200
where `name` = '张三';
update bank_account set balance = balance + 100
where `name` = '李四';

select * from bank_account;

commit;
 
start transaction;

update bank_account set balance = balance - 200
where `name` = '张三';

savepoint sp1;

update bank_account set balance = balance + 100
where `name` = '李四';

savepoint sp2;

rollback to sp2;

start transaction;

update bank_account set balance = balance - 200
where `name` = '张三';

savepoint sp1;

update bank_account set balance = balance + 100
where `name` = '李四';

savepoint sp2;

rollback to sp1;

start transaction;

update bank_account set balance = balance - 200
where `name` = '张三';

savepoint sp1;

update bank_account set balance = balance + 100
where `name` = '李四';

savepoint sp2;

rollback;

show variables like 'autocommit';

set autocommit = 0;

set autocommit = 1;

set autocommit = on;

set autocommit = off;

select @@global.transaction_isolation;

select @@session.transaction_isolation;

set global transaction_isolation = 'serializable';

set @@global.transaction_isolation = 'repeatable-read';

set @@global.transaction_isolation = 'read-committed';

set global transaction_isolation = 'read-uncommitted';

set global transaction isolation level read uncommitted; 

set session transaction isolation level serializable;

set session transaction isolation level read uncommitted;

















